<?php
/**
 * Created by PhpStorm.
 * User: Edward
 * Date: 2019/5/31
 * Time: 13:23
 */
namespace app\admin\controller\warehouse;

use app\admin\BaseController;
use app\admin\model\WarehouseLog as WarehouseLogService;
use app\Validate\PageMustValidate;
use think\Request;

/**
 * 仓库日志方法
 * Class Warehouse
 * @package app\admin\controller\warehouse
 */
class WarehouseLog extends BaseController {
    /**
     * 查看仓库操作日志
     * 可选入参 product_id,warehouse_id,admin_id
     * @param Request $request
     * @return \think\response\Json
     * @throws \app\lib\exception\ParameterException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getProductLog(Request $request){
        (new PageMustValidate()) ->goCheck();
        $post = $request->post();
        $where = [];
        if(isset($post["product_id"]) && $post["product_id"] != 0){
            $where["product_id"] = $post["product_id"];
        }
        if(isset($post["warehouse_id"]) && $post["warehouse_id"] != 0){
            $where["warehouse_id"] = $post["warehouse_id"];
        }
        if(isset($post["admin_id"]) && $post["admin_id"] != 0){
            $where["admin_id"] = $post["admin_id"];
        }
        $warehouseLogService = new WarehouseLogService();
        $list = $warehouseLogService
            ->field("om_warehouse_log.*,om_admin.username")
            ->where($where)
            ->join("om_admin","om_warehouse_log.admin_id = om_admin.id")
            ->paginate($post['page_number'], false, ['page' => $post['page']]);
        return writeJson(200,$list);
    }
}